package com.it.data_linkedList.leetcode;

/**
 * @Author: Coke
 * @DateTime: 2023/06/04/22:12
 * @注释: 反转单向链表
 **/
public class E01LeetCode206 {
    private static ListNode root = null;
    
    /**
     * @return ListNode
     * @作者: Coke
     * @注释: 初始化
     * @DateTime: 2023/6/4 22:30
     */
    public static ListNode init () {
        for (int i = 5; i >= 1; i--) {
            ListNode node = new ListNode(i, root);
            root = node;
        }
        return root;
    }
    
    public static ListNode reverseList (ListNode o1) {
        
        if (o1 == null || o1.next == null) {
            return o1;
        }
        ListNode o2 = o1.next;
        ListNode n1 = o1;
        while (o2 != null) {
            o1.next = o2.next;
            o2.next = n1;
            n1 = o2;
            o2 = o1.next;
        }
        return n1;
    }
    
    
}
